/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-07-20 16:29:22
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-07 15:31:04
 */
import React, { Component } from 'react';
import { Row, Col } from 'antd';
import { observer, inject } from 'mobx-react';
import { toJS } from 'mobx';
import { hashHistory } from 'react-router';


@inject('centerStore')
@observer
class LayoutLeftComponent extends Component {
  componentDidMount() {
    const { centerStore } = this.props;
    centerStore.buildCountOfOdocType();
  }

  render() {
    const { centerStore } = this.props;
    let countOfOdocType = toJS(centerStore.countOfOdocType);
    let rows = [];
    if (countOfOdocType.dataList) {
      countOfOdocType.dataList.sort((a, b) => b.count - a.count);
      countOfOdocType.dataList.map((data, index) => {
        if (index < 10) {
          rows.push(
            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@x952t3@${index}`} span="12">
              <div onClick={() => this.jumpToLibrary(data.odoctype)} title={data.showname} className="left_c1">
                <span className="span1">{data.showname}</span>
                <span className="span2">{data.count}</span>
              </div>
            </Col>,
          );
        }
      });
    }

    return (
      <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@k7fzlc`} className="wea-odoc-center-left-row">
        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@srazyp`}>
          <div className="wea-info-group-new">
            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@ovahct`} className="wea-info-group-new-title">
              <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@5c2uev`}>
                <div className="wea-info-group-new-title-info">&nbsp;&nbsp;{countOfOdocType.showname}（{countOfOdocType.totalCount}）</div>
              </Col>
            </Row>
            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@80gzpr`} className="wea-info-group-new-content" >
              <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@5gp9qj`}>
                {rows}
              </Col>
            </Row>
          </div>
        </Col>
      </Row>
    );
  }

  jumpToLibrary(odoctype) {
    let params = {
      conditionKeys: 'odoctype',
      conditionVals: odoctype,
    };
    let path = {
      pathname: '/main/offical/odocLibraryNew',
      query: params,
    };

    hashHistory.push(path);
  }
}
export default LayoutLeftComponent;
